package pl.andrzejag.seleniumtests;

import static org.junit.Assert.*;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SeleniumTestOnet extends SeleniumBase {
	
	private String baseUrl = "http://onet.pl";


	@Before
	public void setUp() throws Exception {
		driver = new FirefoxDriver();
		// driver = new HtmlUnitDriver();
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		driver.get(baseUrl);
	}
	
	@Ignore
	@Test
	public void shouldVerifyMenuOnet(){
		assertEquals("Onet - informacje, rozrywka, emocje", driver.getTitle());
		List<WebElement> menu_i = driver.findElements(By.xpath("//div[@id='topNavD']/ul/li"));
		System.out.println("menu_i "+menu_i.size());
		for (int i = 1; i < menu_i.size(); i++) {
			List<WebElement> menu_j = driver.findElements(By.xpath("//div[@id='topNavD']/ul/li["+i+"]/div/ul/li"));
			System.out.println("menu_j "+menu_j.size());
			for (int j = 1; j < menu_j.size(); j++) {
				
				String path_i="//div[@id='topNavD']/ul/li";
				if(i>1) path_i =path_i+"["+i+"]";
				
				String path_j=path_i + "/div/ul/li";
				if(j>1) path_j = path_j+"["+j+"]";
				
				String path_a=path_j + "/a";
				click(By.xpath(path_a));
			}
		}
	}


}
